package com.objectproject.main.service.subsystem.loader;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.objectproject.main.dao.MyPropertyDAOImpl;
import com.objectproject.main.model.MyObject;
import com.objectproject.main.model.MyProperty;

@Service
public class PropertyDetailLoader {
	
	@Autowired
	MyPropertyDAOImpl myPropertyDAOImpl;
	
	//이전에 의미상 프로퍼티 선택이 완료되었을 것이므로 단지 선택만 한다.
	public void loadPropertyDetails(MyObject myObject,  int localeId){
		loadPropertyDetails(myObject.getMyProperties(), localeId);
	}
	
	public void loadPropertyDetails(ArrayList<MyProperty> myProperties, int localeId){
		for(MyProperty myProperty:myProperties){
			MyProperty myPropertyDetail = myPropertyDAOImpl.selectMyPropertyDetailOf(myProperty, localeId);
			loadPropertyDetailEasy(myProperty, myPropertyDetail);
		}
	}
	
	public void loadPropertyDetail(MyProperty myProperty,  int localeId){
		MyProperty myPropertyDetail = myPropertyDAOImpl.selectMyPropertyDetailOf(myProperty, localeId);
		loadPropertyDetailEasy(myProperty, myPropertyDetail);
			
	}
	
	//helper
	private void loadPropertyDetailEasy(MyProperty myProperty, MyProperty myPropertyDetail){
		myProperty.setLabel(myPropertyDetail.getLabel());
		myProperty.setValueId(myPropertyDetail.getValueId());
		myProperty.setHelpText(myPropertyDetail.getHelpText());
		myProperty.setPriority(myPropertyDetail.getPriority());
	}
}
